/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils.nucleo;

import utils.observer.login.UsuarioObserver;
import models.Pessoa;
import ui.Principal;
import utils.observer.login.PrincipalObserver;
import utils.observer.login.UsuarioSubject;

/**
 *
 * @author Amauri
 */
public class Nucleo {
    
    private Pessoa loggedUser = null;
    
    private static Nucleo instance = null;
    private static UsuarioSubject userSubject = new UsuarioSubject();
    
    private Principal main = new Principal();
    
    private Nucleo(){
        userSubject.registerObserver(new UsuarioObserver());
        userSubject.registerObserver(new PrincipalObserver());
    };
    
    public static Nucleo getInstance() {
        if ( instance == null ) {
            instance = new Nucleo();
            userSubject.notifyObservers();
        }
        
        return instance;
    }
    
    public UsuarioSubject getUserSubject() {
        return this.userSubject;
    }
    
    public boolean isUserLogged() {
        return ( loggedUser != null );
    }
    
    public Principal getPrincipal() {
        return main;
    }
    
    public void setUser(Pessoa u) {
        this.loggedUser = u;
        userSubject.notifyObservers();
    }
    
    public Pessoa getUser() {
        return this.loggedUser;
    }
}